package org.example.everyday;

public class Lc204 {

    public static void main(String[] args) {
        Lc204 lc204 = new Lc204();
        lc204.countPrimes(10);
    }

    public int countPrimes(int n) {
        boolean[] notPrime = new boolean[n + 1];
        int count = 0;
        for(int i = 2; i < n; i++){
            if(notPrime[i]){
                continue;
            }
            System.out.println(i);
            count++;
            //在每次找到一个素数时，就把素数的所有倍数的值都排除掉
            for(long j = (long)i * i; j < n; j += i){
                notPrime[(int)j] = true;
            }
        }
        return count;
    }
}
